package com.how.diaryfriend.ui.home.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.how.diaryfriend.R;
import com.how.diaryfriend.data.Diary;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;


public class DiaryAdapter extends RecyclerView.Adapter<DiaryAdapter.ViewHolder> {
    private static final String TAG = "DIARY";
    private List<Diary> allDiary = new ArrayList<>();


    void setAllWords(List<Diary> allWords) {
        this.allDiary = allWords;
    }

    @NonNull
    @Override
    public DiaryAdapter.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adopt_home, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull DiaryAdapter.ViewHolder holder, int position) {
        Diary diary = allDiary.get(position);
        holder.content.setText(diary.getContent());
        holder.title.setText(diary.getTitle());
        holder.day.setText(diary.getDay());
        holder.week.setText(diary.getWeek());
        holder.itemView.setOnClickListener(v -> Log.d(TAG, "点击进入详情页"));
    }

    @Override
    public int getItemCount() {
        return allDiary.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView day,title,content,week;

        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            this.day = itemView.findViewById(R.id.diary_day);
            this.week = itemView.findViewById(R.id.diary_week);
            this.content = itemView.findViewById(R.id.diary_cotent);
            this.title = itemView.findViewById(R.id.diary_title);
        }
    }
}
